// 自动更新应用环境标识
const fs = require('fs')
const path = require('path')

const NODE_ENV = process.env.NODE_ENV 
const WP_ENV = process.env.WP_ENV ||''

const ENV_FILE = './src/utils/env.ts'




const injectVersion = async ( label ) => {
  const ENV_FILE = path.join(__dirname, './', './src/utils/env.ts')
  let file = fs.readFileSync(ENV_FILE, 'utf8')
  file = file.replace(/(const\s+ENV_NAME\s+\=\s+)(\'[^\']*\')/ig,`$1'${label}'`)
  fs.writeFileSync(ENV_FILE, file)
  console.log('写入版本标识成功：',label)
}
if( WP_ENV ){
  injectVersion(WP_ENV)
}else{
  injectVersion('')
}
